/*
ID: icerupt1
PROG: numtri
LANG: C++11
*/
#include <fstream>
#include <iostream>
using namespace std;

int const maxn = 1001;
int f[maxn];
int da[maxn];
int n;

int main()
{
	ifstream fin {"numtri.in" };
	ofstream fout{"numtri.out"};

	fin >> n;
	fin >> f[0];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < i+1; j++) fin >> da[j];
		f[i] = f[i-1] + da[i];
		for (int j = i-1; j > 0; j--) f[j] = max(f[j], f[j-1]) + da[j];
		f[0] += da[0];
	}

	int ans = 0;
	for (int i = 0; i < n; i++) if (f[i] > ans) ans = f[i];
	fout << ans << "\n";
}
